package com.demo.controller.system;


import com.demo.dao.Result;
import com.demo.pojo.system.Dept;
import com.demo.service.system.DeptService;
import com.demo.tree.DeptTree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/dept")
public class DeptController {
    @Autowired
    private DeptService deptService;

    @PostMapping
    private Result<List<Dept>> addDept(@RequestBody Dept dept) {
        deptService.save(dept);
        return Result.success();
    }
    @DeleteMapping
    private Result deleteDept(@RequestParam int id) {
        deptService.removeById(id);
        return Result.success();
    }
    @PutMapping
    private Result updateDept(@RequestBody Dept dept) {
        deptService.updateById(dept);
        return Result.success();
    }
    @GetMapping
    private Result<List<Dept>> getDeptList() {
        List<Dept> list = deptService.lambdaQuery().select().list();
        DeptTree deptTree = new DeptTree();
        deptTree.createTree(list,0);
        return Result.success(list);
    }
}
